package DMSXL._2024.BackTracking;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class BackTracking {
    public static void main(String[] args) {

    }
    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
        backTracking(n,k,1);
        return result;
    }

    public void backTracking(int n ,int k,int startIndex){
        if(path.size() == k){
            result.add(new ArrayList<>(path));
            return;
        }
        for (int i = startIndex; i <= n; i++) {
            path.add(i);
            backTracking(n,k,i + 1);
            path.removeLast();
        }
    }
}
